#include <Windows.h>
#include <thread>
#include <titanfall2/Context.h>
#include <titanfall2/UserCmd.h>


void CreateMove(titanfall2::CUserCmd* cmd)
{
    if (GetAsyncKeyState(VK_F1) & 0x8000)
        cmd->command_number = 0x7FFFFFFF;

    if (GetAsyncKeyState(VK_SHIFT) & 0x8000)
        *(float*)((uintptr_t)cmd + 0xAC) += 0.10f;
}

namespace era
{
    void MainThread(HMODULE hModule)
    {
        auto& context = titanfall2::Context::Get();
        context.SetOnCreateMove(CreateMove);

        while (!GetAsyncKeyState(VK_END))
        {
             std::this_thread::sleep_for(std::chrono::milliseconds(1000));
        }
        FreeLibrary(hModule);
    }
} // namespace era


[[maybe_unused]]
BOOL APIENTRY DllMain(HMODULE hModule, DWORD callReason, [[maybe_unused]] LPVOID lpReserved)
{
    if (callReason == DLL_PROCESS_ATTACH)
        std::thread(era::MainThread, hModule).detach();

    return true;
}